# -*- mode: python -*-

Import("env")

env.Library('repl_settings',
            'repl_settings.cpp',
            LIBDEPS=[
                '$BUILD_DIR/mongo/base/base',
                '$BUILD_DIR/mongo/server_parameters'
            ])

env.Library('rslog',
            'rslog.cpp',
            LIBDEPS=[
                '$BUILD_DIR/mongo/logger/logger',
            ])

env.Library(
    'network_interface_impl',
    'network_interface_impl.cpp',
    LIBDEPS=[
        '$BUILD_DIR/mongo/base/base',
        '$BUILD_DIR/mongo/clientdriver'
        ])

env.Library('replication_executor',
            [
                'replication_executor.cpp',
                'scatter_gather_algorithm.cpp',
                'scatter_gather_runner.cpp',
            ],
            LIBDEPS=['$BUILD_DIR/mongo/foundation',
                     '$BUILD_DIR/mongo/hostandport'])

env.CppUnitTest('replication_executor_test',
                'replication_executor_test.cpp',
                LIBDEPS=['replication_executor',
                         'replmocks'])

env.Library('topology_coordinator',
            [
                'heartbeat_response_action.cpp',
                'topology_coordinator.cpp',
            ],
            LIBDEPS=[
                'repl_coordinator_interface',
            ])

env.Library('topology_coordinator_impl',
            [
                'member_heartbeat_data.cpp',
                'topology_coordinator_impl.cpp',
            ],
            LIBDEPS=[
                'replication_executor',
                'repl_settings',
                'rslog',
                'topology_coordinator',
            ])

env.CppUnitTest('repl_set_heartbeat_response_test',
                'repl_set_heartbeat_response_test.cpp',
                LIBDEPS=['replica_set_messages'])

env.CppUnitTest('topology_coordinator_impl_test',
                'topology_coordinator_impl_test.cpp',
                LIBDEPS=['topology_coordinator_impl',
                         'replica_set_messages'])

env.Library('repl_coordinator_impl',
            [
                'check_quorum_for_config_change.cpp',
                'elect_cmd_runner.cpp',
                'freshness_checker.cpp',
                'repl_coordinator_impl.cpp',
                'repl_coordinator_impl_elect.cpp',
                'repl_coordinator_impl_heartbeat.cpp',
                'replica_set_config_checks.cpp',
            ],
            LIBDEPS=['$BUILD_DIR/mongo/db/common',
                     '$BUILD_DIR/mongo/db/index/index_descriptor',
                     '$BUILD_DIR/mongo/fail_point',
                     '$BUILD_DIR/mongo/foundation',
                     '$BUILD_DIR/mongo/global_environment_experiment',
                     '$BUILD_DIR/mongo/global_optime',
                     '$BUILD_DIR/mongo/server_options_core',
                     'repl_coordinator_interface',
                     'replica_set_messages',
                     'replication_executor',
                     'rslog',
                     'topology_coordinator',
                 ])

env.Library('repl_coordinator_test_fixture',
            [
                'repl_coordinator_test_fixture.cpp',
            ],
            LIBDEPS=[
                'repl_coordinator_impl',
                'replmocks',
                'topology_coordinator_impl',
            ])

env.CppUnitTest('repl_coordinator_impl_test',
                [
                    'repl_coordinator_impl_test.cpp',
                ],
                LIBDEPS=['repl_coordinator_test_fixture'])

env.CppUnitTest('replica_set_config_checks_test',
                'replica_set_config_checks_test.cpp',
                LIBDEPS=[
                    'repl_coordinator_impl',
                    'replmocks'
                ])

env.CppUnitTest('check_quorum_for_config_change_test',
                'check_quorum_for_config_change_test.cpp',
                LIBDEPS=[
                    'repl_coordinator_impl',
                    'replication_executor',
                    'replmocks',
                ])

env.CppUnitTest('freshness_checker_test',
                'freshness_checker_test.cpp',
                LIBDEPS=['repl_coordinator_impl',
                         'replica_set_messages',
                         'replmocks'])

env.CppUnitTest('elect_cmd_runner_test',
                'elect_cmd_runner_test.cpp',
                LIBDEPS=['repl_coordinator_impl',
                         'replica_set_messages',
                         'replmocks'])

env.CppUnitTest('repl_coordinator_impl_elect_test',
                'repl_coordinator_impl_elect_test.cpp',
                LIBDEPS=['repl_coordinator_test_fixture'])

env.CppUnitTest('repl_coordinator_impl_heartbeat_test',
                'repl_coordinator_impl_heartbeat_test.cpp',
                LIBDEPS=['repl_coordinator_test_fixture'])

env.CppUnitTest('repl_coordinator_impl_reconfig_test',
                'repl_coordinator_impl_reconfig_test.cpp',
                LIBDEPS=['repl_coordinator_test_fixture'])

env.Library('repl_coordinator_interface',
            ['repl_coordinator.cpp',
             'repl_coordinator_external_state.cpp',
             'repl_set_seed_list.cpp'],
            LIBDEPS=[
                '$BUILD_DIR/mongo/hostandport',
            ])

env.Library('repl_coordinator_global',
            'repl_coordinator_global.cpp',
            LIBDEPS=['repl_coordinator_interface'])

env.Library('replmocks',
            [
                'network_interface_mock.cpp',
                'operation_context_repl_mock.cpp',
                'repl_coordinator_external_state_mock.cpp',
                'repl_coordinator_mock.cpp',
            ],
            LIBDEPS=[
                '$BUILD_DIR/mongo/db/concurrency/lock_mgr',
                'repl_coordinator_interface',
                'replication_executor',
            ])

env.Library('replica_set_messages',
            [
                'handshake_args.cpp',
                'is_master_response.cpp',
                'member_config.cpp',
                'repl_set_heartbeat_args.cpp',
                'repl_set_heartbeat_response.cpp',
                'replica_set_config.cpp',
                'replica_set_tag.cpp',
                'update_position_args.cpp',
            ],
            LIBDEPS=[
                '$BUILD_DIR/mongo/bson',
                '$BUILD_DIR/mongo/hostandport',
                '$BUILD_DIR/mongo/db/common',
            ])

env.CppUnitTest('replica_set_config_test',
                [
                    'member_config_test.cpp',
                    'replica_set_config_test.cpp',
                    'replica_set_tag_test.cpp',
                ],
                LIBDEPS=['replica_set_messages'])

env.CppUnitTest('isself_test',
                [
                    'isself_test.cpp',
                ],
                LIBDEPS=[
                    '$BUILD_DIR/mongo/serveronly',
                    '$BUILD_DIR/mongo/coreserver',
                    '$BUILD_DIR/mongo/coredb',
                ],
                NO_CRUTCH = True)
